﻿using DVM.DB.Model;
using DVM.DV;
using DVM.DV.Extensions;
using DVM.DV.Model;
using DVM.VM;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DVM.DB.DataQuery
{
    [PropertySet(DBField.ProductImageId)]
    public class ImageQuery : DVContext<int, ImageViewModel>
    {
        public ImageQuery(InitInfo initInfo) : base(initInfo)
        {

        }


        public override Dictionary<int, ImageViewModel> ConvertView()
        {
            var result = new Dictionary<int, ImageViewModel>();
            var keys = GetPropertyValue();
            var queryData = QueryImageViewFromDB(keys);
            return queryData.Distinct().ToDictionary(x => x.Id, x => new ImageViewModel
            {
                Id = x.Id,
                ImageUrl = x.ImageUrl,
            });
        }

        /// <summary>
        /// 数据查询
        /// </summary>
        /// <param name="keys"></param>
        /// <returns></returns>
        public static List<Image> QueryImageViewFromDB(List<int> keys)
        {
            return DBData.GetImageQuery().Where(x => keys.Contains(x.Id)).Distinct().ToList(); 
        }
    }
}
